unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

const
  N = 25;
  D= 10;

type
  fr = record
    x, y: integer;
  end;
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure Image1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.Color:= clWhite;
end;

procedure TForm1.Image1Click(Sender: TObject);
var
  i, j, m, a, b, sum, frfr, r: integer;
  arr: array of fr;
begin
  setlength (arr, n);
  m:= 1;
  frfr:= 1;
  repeat
    frfr:= frfr*2;
    inc(m);
  until (n<frfr*2);

  a:= Image1.Width div frfr;

  sum:= 0;
  frfr:= 1;

  for i := 0 to m-1 do
  begin
    b:= (Image1.Width div (frfr*2));
    arr[sum+1].x:= b;
    arr[sum+1].y:= a*i + (a div 2);
    inc (sum);
    while (sum<frfr*2-1) and (sum<N) do
    begin
      arr[sum+1].x:= arr[sum].x +2*b;
      arr[sum+1].y:= arr[sum].y;
      inc(sum);
    end;
    frfr:= frfr*2;
  end;

  r:= (a-D) div 2;
  Form1.Canvas.Pen.Color:= clBlack;
  Form1.Canvas.Brush.Color:= clBlack;
  for i := 1 to n do
  begin
    Form1.Canvas.Ellipse(arr[i].x-r, arr[i].y-r, arr[i].x +r, arr[i].y+r);
    Form1.Canvas.MoveTo(arr[i].x, arr[i].y);
    if (2*i+1<=n) then
      Form1.Canvas.LineTo(arr[2*i+1].x, arr[2*i+1].y);
    Form1.Canvas.MoveTo(arr[i].x, arr[i].y);
    if (2*i<=n) then
      Form1.Canvas.LineTo(arr[2*i].x, arr[2*i].y);
  end;
end;

end.
